﻿#ifndef _FD_COMMONSTRUCT_H_
#define _FD_COMMONSTRUCT_H_ 

#include "../dll_cfg.h"
#include "kernel/time/time.h"
#include "udataset/mdb/ModelTree.h"

namespace FD
{
	namespace Utility
	{
		namespace Dataset
		{
			class ModelDB;

			struct FD_XDataset_Export PropertySet
			{
				String guid;
				String name;

				std::vector<std::pair<String, String>> keyVal;
			};

			struct FD_XDataset_Export PropertyInsert
			{
				String guid;
				String name;
				String key;
				String val;
			};

			typedef std::vector<PropertyInsert> PropertyInsertBatch;

			struct FD_XDataset_Export PropertyRefInsert
			{
				uint32 compFDID;
				uint32 objectFDID;
				uint32 refTypeID;
				uint32 proFDID;
				String compGuid;
				String compName;

				PropertyRefInsert()
				{
					compFDID = 0;
					objectFDID = 0;
					refTypeID = 0;
					proFDID = 0;
				}
			};

			typedef std::vector<PropertyRefInsert> PropertyRefInsertBatch;

			typedef std::vector<PropertySet> PropertySetVec;

			struct FD_XDataset_Export OpeningElem
			{
				String name;
				String guid;
				String objectType;
				String objectPlacement;
				String layerGuid;

				PropertySetVec proSetVec;
			};

			typedef std::vector<OpeningElem> LinkOpenings;

			struct FD_XDataset_Export CompType
			{
				uint32 typeID;
				String name;
			};

			typedef std::vector<CompType> CompTypeVec;

			struct FD_XDataset_Export CompTypeAttr
			{
				String name;
				String guid;
				String tag;
				String predefinedType;

				PropertySetVec proSetVec;
			};

			struct FD_XDataset_Export CompAttr
			{
				String name;
				String guid;
				String objectType;
				String objectPlacement;
				String layerGuid;
				String tag;
				uint32 floorFDID;

				LinkOpenings linkOpenings;

				CompTypeAttr linkCompType;

				PropertySetVec proSetVec;

				CompAttr()
				{
					floorFDID = 0;
				}
			};

			struct FD_XDataset_Export CompInfo
			{
				String name;
				String guid;
			};

			typedef std::vector<CompInfo> CompInfoVec;

			struct FD_XDataset_Export CompInfoPage
			{
				friend class ModelDB;

				CompInfoVec result;

				CompInfoPage()
				{
					currentOffset = 0;
					recordNumPerPage = 0;
					modelID = 0;
					modelDB = NULL;
					bNeedNext = true;
					totalNum = 0;
				}

				uint32 getTotalNum(){return totalNum;}

				//pageNo=0代表一直往下翻，不=0代表直接跳到pageNo页，非法页返回false
				bool nextPage(uint32 pageNo = 0);

			private:
				String origSql;
				uint32 modelID;
				uint32 currentOffset;
				uint32 recordNumPerPage;
				bool bNeedNext;
				uint32 totalNum;
				ModelDB* modelDB;
			};

			struct FD_XDataset_Export PModelInfo
			{
				uint32 modelID;
				String modelName;
			};

			typedef std::vector<PModelInfo> PModelInfoVec;

			struct FD_XDataset_Export PModelInfoPage
			{
				friend class ModelDB;

				PModelInfoVec result;

				PModelInfoPage()
				{
					currentOffset = 0;
					recordNumPerPage = 0;
					modelID = 0;
					modelDB = NULL;
					bNeedNext = true;
					totalNum = 0;
				}

				uint32 getTotalNum(){return totalNum;}

				//pageNo=0代表一直往下翻，不=0代表直接跳到pageNo页，非法页返回false
				bool nextPage(uint32 pageNo = 0);

			private:
				String origSql;
				uint32 modelID;
				uint32 currentOffset;
				uint32 recordNumPerPage;
				uint32 totalNum;
				bool bNeedNext;
				ModelDB* modelDB;
			};

			enum EnumTaskType
			{
				TT_Structure=0, // 构造
				TT_Dismantle, // 拆除
				TT_Temporary // 临时
			};

			struct FD_XDataset_Export Task
			{
				String taskName; //任务名称
				uint32 taskID;  //任务ID，由插入后返回
				uint32 parentTaskID;  //父节点组ID，如果没有父则写0
				FD::Kernel::Time planS; //计划开始时间
				FD::Kernel::Time planE; //计划结束时间
				FD::Kernel::Time actualS; //实际开始时间
				FD::Kernel::Time actualE; //实际结束时间
				EnumTaskType taskType; //任务类别
				String guid; //任务guid
				Real totalPrice; //总价
				String desc; //描述
				bool bActive; //是否激活
				Real percent; //百分比 [0, 1]

				std::vector<Task> childTask;

				Task()
				{
					taskID = 0;
					parentTaskID = 0;
					planS = planE = actualS = actualE = FD::Kernel::Time::currentTime();
					totalPrice = 0.0;
					bActive = true;
					taskType = TT_Structure;
					percent = 0.0;
				}
			};

			typedef std::vector<Task> TaskVec;

			struct FD_XDataset_Export TaskPage
			{
				friend class ModelDB;

				TaskVec result;

				TaskPage()
				{
					currentOffset = 0;
					recordNumPerPage = 0;
					modelID = 0;
					modelDB = NULL;
					bNeedNext = true;
					totalNum = 0;
				}

				uint32 getTotalNum(){return totalNum;}

				//pageNo=0代表一直往下翻，不=0代表直接跳到pageNo页，非法页返回false
				bool nextPage(uint32 pageNo = 0);

			private:
				String origSql;
				uint32 modelID;
				uint32 currentOffset;
				uint32 recordNumPerPage;
				bool bNeedNext;
				uint32 totalNum;
				ModelDB* modelDB;
			};

			struct FD_XDataset_Export Floor
			{
				uint32 floorFDID;
				String guid;
				String name;
				String objectPlacement;
				String longName;
				String compositionType;
				String elevation;

				Floor()
				{
					floorFDID = 0;
				}
			};

			typedef std::vector<Floor> Floors;

			struct FD_XDataset_Export ModelTreePage
			{
				friend class ModelDB;

				ModelTreeVec result;

				ModelTreePage()
				{
					currentOffset = 0;
					recordNumPerPage = 0;
					modelID = 0;
					modelDB = NULL;
					bNeedNext = true;
					totalNum = 0;
				}

				~ModelTreePage();

				uint32 getTotalNum(){return totalNum;}

				//pageNo=0代表一直往下翻，不=0代表直接跳到pageNo页，非法页返回false
				bool nextPage(uint32 pageNo = 0);

			private:
				String origSql;
				uint32 modelID;
				uint32 currentOffset;
				uint32 recordNumPerPage;
				bool bNeedNext;
				uint32 totalNum;
				ModelDB* modelDB;
			};


			enum LikeColumn
			{
				LC_PropertyKey=0,
				LC_PropertyValue
			};
		}
	}
}


#endif
